import { useEffect, useState, useRef } from 'react';
import { Button, Card, Form, message, Popconfirm, Space } from 'antd';
import { ProForm, ProFormDatePicker } from '@ant-design/pro-components';
import {
  delChengJiaosApi,
  delWeiTuosApi,
  resetSyncDataApi,
  tongBuChengJiaoApi,
  tongBuPositionsApi,
  tongBuWeituoApi,
} from '@/api';
import { useRequest } from 'ahooks';
import dayjs from 'dayjs';

// const shiBa = dayjs().format('YYYY-MM-DD 18:00:00');
const shiBa = dayjs().format('2025-04-11 24:00:00');
export default function SyncWeituo() {
  useEffect(() => {}, []);

  // ==== 历史委托
  // 同步历史委托
  const { loading: loadingWeituo, run: tongBuWeituo } = useRequest(
    async (params = {}) => {
      const res = await tongBuWeituoApi(params);
      console.log('res: 同步历史委托', res.data);
      console.log('kaifadata: ', res.data.kaifadata);
      const list = res.data.timelist;
      console.log('list: ', list);
    },
    { manual: true },
  );

  // 删除历史委托
  const { loading: loadingDelWeituo, run: delWeituo } = useRequest(
    async (params = {}) => {
      const res = await delWeiTuosApi(params);
      console.log('res: 删除历史委托', res.data);
    },
    { manual: true },
  );

  // 同步成交记录
  const { loading: loadingCJiao, run: tongBuChengJiao } = useRequest(
    async (params = {}) => {
      const res = await tongBuChengJiaoApi(params);
      console.log('res: 同步成交记录', res.data);
    },
    { manual: true },
  );

  // 删除成交记录
  const { loading: loadingDelCJiao, run: delChengJiao } = useRequest(
    async (params = {}) => {
      const res = await delChengJiaosApi(params);
      console.log('res: 删除成交记录', res.data);
    },
    { manual: true },
  );

  return (
    <div>
      <Card>
        <Space>
          <Button loading={loadingWeituo} onClick={() => tongBuWeituo({ date: shiBa })}>
            同步历史委托
          </Button>
          <Button loading={loadingDelWeituo} onClick={() => delWeituo({ date: shiBa })} danger>
            删除历史委托
          </Button>
          <Button loading={loadingCJiao} onClick={() => tongBuChengJiao({ date: shiBa })}>
            同步成交记录
          </Button>
          <Button loading={loadingDelCJiao} onClick={() => delChengJiao({ date: shiBa })} danger>
            删除成交记录
          </Button>
        </Space>
      </Card>
    </div>
  );
}
